﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Spread.Common.Features.Sample;
using Spread.Calculation.Properties;
using GrapeCity.Spreadsheet;
using FarPoint.Win.Spread;

namespace Spread.Calculation.Features
{
    public partial class FormulaTracing : BaseSampleControl
    {
        public FormulaTracing()
        {  
            InitializeComponent(); 
            using (System.IO.MemoryStream s = new System.IO.MemoryStream(Resources.SudokuSolver))
            {
                fpSpread1.OpenExcel(s);
                // fix up columns
                fpSpread1.AllowCellOverflow = false;
                IWorkbook wb = fpSpread1.AsWorkbook();
                IWorksheet ws = wb.ActiveSheet;
                // intialize a puzzle
                const object O = null;
                ws.SetValue(4, 1, new object[,] { { 3, O, 2, O, 7, O, 5, O, 4 },
                                                  { O, O, O, O, O, O, O, O, O },
                                                  { O, O, 6, 2, 5, 4, O, O, O },
                                                  { O, 9, O, O, O, O, 6, O, O },
                                                  { O, O, 8, 9, 6, 5, 1, O, O },
                                                  { O, O, 5, O, O, O, O, 2, O },
                                                  { O, O, O, 1, 9, 7, 8, O, O },
                                                  { O, O, O, O, O, O, O, O, O },
                                                  { 5, O, 7, O, 8, O, 2, O, 6 } });

                AutoFitColumn(0, 8);
                AutoFitColumn(22,22);
                AutoFitColumn(30, 30);
                AutoFitColumn(39, 39);
                AutoFitColumn(48, 48);
                AutoFitColumn(52, 52);                
                // unprotect sheet so formulas can be edited
                ws.Unprotect(null);
                // setup iterations and calculation hokey
                wb.WorkbookSet.CalculationEngine.Iterative = true;
                wb.WorkbookSet.CalculationEngine.MaximumIterations = 1;
                fpSpread1.GetActionMap().Put("Recalculate", new RecalculateAction());
                fpSpread1.GetInputMap(InputMapMode.WhenFocused).Put(new Keystroke(Keys.F9, Keys.None), "Recalculate");
            }
        }
        private void AutoFitColumn(int column, int column2)
        {
            PreferredSizeColumnOptions options = fpSpread1.AutoFitColumnOptions | PreferredSizeColumnOptions.IncludeHidden | PreferredSizeColumnOptions.ExcludeHeaders;
            SheetView sheetView = fpSpread1.ActiveSheet;
            for (int c = column; c <= column2; c++)
            {
                sheetView.SetColumnVisible(c, true);
                sheetView.SetColumnWidth(c, (int)sheetView.GetPreferredColumnWidth(c, true, true, true));
            }
        }

        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = "Excel Spreadsheet (*.xlsx;*.xlsm;*.xls)|*.xlsx;*.xlsm;*.xls|All Files (*.*)|*.*";
            ofd.FilterIndex = 0;
            ofd.Title = "Open Spreadsheet";
            if (DialogResult.OK == ofd.ShowDialog())
            {
                fpSpread1.Open(ofd.FileName);
                // unprotect sheets so formulas can be edited
                foreach (SheetView sv in fpSpread1.Sheets)
                    sv.Protect = false;
            }
        }

      

        private void ShowDependentsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fpSpread1.ShowDependents(fpSpread1.ActiveSheetIndex, fpSpread1.ActiveSheet.ActiveRowIndex, fpSpread1.ActiveSheet.ActiveColumnIndex);
        }

        private void ShowPrecedentsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            fpSpread1.ShowPrecedents(fpSpread1.ActiveSheetIndex, fpSpread1.ActiveSheet.ActiveRowIndex, fpSpread1.ActiveSheet.ActiveColumnIndex);
        }

        private void RemoveArrowsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < fpSpread1.Sheets.Count; i++)
            {
                fpSpread1.HideDependents(i);
                fpSpread1.HidePrecedents(i);
            }
        }

        private void GenerateReportToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int row, rowStart;
            IWorkbook wb = fpSpread1.AsWorkbook();
            IWorkbook wb2 = fpSpread2.AsWorkbook();
            IWorksheet wks = wb2.ActiveSheet;
            IRange targetCell = wb.ActiveSheet.Cells[fpSpread1.ActiveSheet.ActiveRowIndex, fpSpread1.ActiveSheet.ActiveColumnIndex];
            if (!(bool)targetCell.HasFormula)
            {
                MessageBox.Show("You must select a cell containing a formula to analyze first!");
                return;
            }
            IAreas direct_dependents = targetCell.DirectDependents.Areas;
            IAreas direct_precedents = targetCell.DirectPrecedents.Areas;
            IAreas all_dependents = targetCell.Dependents.Areas;
            IAreas all_precedents = targetCell.Precedents.Areas;
            SheetView sv = fpSpread2.ActiveSheet;
            sv.Reset();
            sv.RowCount = int.MaxValue;
            sv.Cells[0, 0].Text = "Tracing Formula in cell " + targetCell.Address(false, false, ReferenceStyle.A1, false, targetCell) + ":";
            wks.Cells[0, 0].ApplyStyle(BuiltInStyle.Percent60Accent6);
            wks.Cells[0, 0].ApplyStyle(BuiltInStyle.Title);
            wks.Rows[0].AutoFit();
            sv.Cells[1, 0].Text = targetCell.HasArray ? targetCell.FormulaArray : targetCell.Formula;
            sv.Cells[1, 0].ColumnSpan = 2;
            wks.Cells[1, 0].Style.VerticalAlignment = VerticalAlignment.Top;
            wks.Cells[1, 0].Style.WrapText = true;
            sv.SetRowHeight(1, sv.GetPreferredCellSize(1, 0).Height);
            wks.Cells[1, 0].ApplyStyle(BuiltInStyle.Percent20Accent6);
            wks.Cells[1, 0].ApplyStyle(BuiltInStyle.Calculation);

            row = 3;
            sv.Cells[row, 0].Text = "Direct Dependents";
            sv.Cells[row, 0].Note = "Direct Depedents are cells which directly reference the target cell.";
            sv.Cells[row, 0].ColumnSpan = 2;
            wks.Cells[row, 0].ApplyStyle(BuiltInStyle.Percent40Accent6);
            wks.Cells[row, 0].ApplyStyle(BuiltInStyle.Title);
            wks.Rows[row].RowHeight = wks.Rows[0].RowHeight;
            row++;
            rowStart = row;
            sv.Cells[row, 0].Text = "Cell";
            sv.Cells[row, 1].Text = "Formula/Value";
            row++;
            for (int i = 0; i < direct_dependents.Count; row++, i++)
            {
                sv.Cells[row, 0].Text = direct_dependents[i].Address(false, false, ReferenceStyle.A1, false, direct_dependents[i]);
                sv.Cells[row, 1].Text = (bool)direct_dependents[i].HasFormula ? (direct_dependents[i].HasArray ? direct_dependents[i].FormulaArray : direct_dependents[i].Formula) : direct_dependents[i].Text;
            }
            sv.AddTable(rowStart, 0, row - rowStart, 2);
            for (int i = 0; i < direct_dependents.Count; i++)
            {
                if ((bool)direct_dependents[i].HasFormula)
                {
                    wks.Cells[rowStart + 1 + i, 1].ApplyStyle(BuiltInStyle.Calculation);
                    wks.Cells[rowStart + 1 + i, 1].Style.WrapText = true;
                    sv.SetRowHeight(rowStart + 1 + i, sv.GetPreferredCellSize(rowStart + 1 + i, 1).Height);
                }
            }
            row += 2;
            sv.Cells[row, 0].Text = "Direct Precedents";
            sv.Cells[row, 0].Note = "Direct Precedents are cells which are directly referenced in the target cell formula.";
            sv.Cells[row, 0].ColumnSpan = 2;
            wks.Cells[row, 0].ApplyStyle(BuiltInStyle.Percent40Accent6);
            wks.Cells[row, 0].ApplyStyle(BuiltInStyle.Title);
            wks.Rows[row].RowHeight = wks.Rows[0].RowHeight;
            row++;
            rowStart = row;
            sv.Cells[row, 0].Text = "Cell";
            sv.Cells[row, 1].Text = "Formula/Value";
            row++;
            for (int i = 0; i < direct_precedents.Count; row++, i++)
            {
                sv.Cells[row, 0].Text = direct_precedents[i].Address(false, false, ReferenceStyle.A1, false, direct_precedents[i]);
                sv.Cells[row, 1].Text = (bool)direct_precedents[i].HasFormula ? (direct_precedents[i].HasArray ? direct_precedents[i].FormulaArray : direct_precedents[i].Formula) : direct_precedents[i].Text;
            }
            sv.AddTable(rowStart, 0, row - rowStart, 2);
            for (int i = 0; i < direct_precedents.Count; i++)
            {
                if ((bool)direct_precedents[i].HasFormula)
                {
                    wks.Cells[rowStart + 1 + i, 1].ApplyStyle(BuiltInStyle.Calculation);
                    wks.Cells[rowStart + 1 + i, 1].Style.WrapText = true;
                    sv.SetRowHeight(rowStart + 1 + i, sv.GetPreferredCellSize(rowStart + 1 + i, 1).Height);
                }
            }
            if (all_dependents.Count > direct_dependents.Count)
            {
                row += 2;
                sv.Cells[row, 0].Text = "All Dependents";
                sv.Cells[row, 0].Note = "Depedents are cells which directly reference the target cell, and all cells which directly reference those cells, and so on.";
                sv.Cells[row, 0].ColumnSpan = 2;
                wks.Cells[row, 0].ApplyStyle(BuiltInStyle.Percent40Accent6);
                wks.Cells[row, 0].ApplyStyle(BuiltInStyle.Title);
                wks.Rows[row].RowHeight = wks.Rows[0].RowHeight;
                row++;
                rowStart = row;
                sv.Cells[row, 0].Text = "Cell";
                sv.Cells[row, 1].Text = "Formula/Value";
                row++;
                for (int i = 0; i < all_dependents.Count; row++, i++)
                {
                    sv.Cells[row, 0].Text = all_dependents[i].Address(false, false, ReferenceStyle.A1, false, all_dependents[i]);
                    sv.Cells[row, 1].Text = (bool)all_dependents[i].HasFormula ? (all_dependents[i].HasArray ? all_dependents[i].FormulaArray : all_dependents[i].Formula) : all_dependents[i].Text;
                }
                sv.AddTable(rowStart, 0, row - rowStart, 2);
                for (int i = 0; i < all_dependents.Count; i++)
                {
                    if ((bool)all_dependents[i].HasFormula)
                    {
                        wks.Cells[rowStart + 1 + i, 1].ApplyStyle(BuiltInStyle.Calculation);
                        wks.Cells[rowStart + 1 + i, 1].Style.WrapText = true;
                        sv.SetRowHeight(rowStart + 1 + i, sv.GetPreferredCellSize(rowStart + 1 + i, 1).Height);
                    }
                }
            }
            if (all_precedents.Count > direct_precedents.Count)
            {
                row += 2;
                sv.Cells[row, 0].Text = "All Precedents";
                sv.Cells[row, 0].Note = "Precedents are cells which are directly referenced in the target cell formula, and all cells which are directly referenced in those cell formulas, and so on.";
                sv.Cells[row, 0].ColumnSpan = 2;
                wks.Cells[row, 0].ApplyStyle(BuiltInStyle.Percent40Accent6);
                wks.Cells[row, 0].ApplyStyle(BuiltInStyle.Title);
                wks.Rows[row].RowHeight = wks.Rows[0].RowHeight;
                row++;
                rowStart = row;
                sv.Cells[row, 0].Text = "Cell";
                sv.Cells[row, 1].Text = "Formula/Value";
                row++;
                for (int i = 0; i < all_precedents.Count; row++, i++)
                {
                    sv.Cells[row, 0].Text = all_precedents[i].Address(false, false, ReferenceStyle.A1, false, all_precedents[i]);
                    sv.Cells[row, 1].Text = (bool)all_precedents[i].HasFormula ? (all_precedents[i].HasArray ? all_precedents[i].FormulaArray : all_precedents[i].Formula) : all_precedents[i].Text;
                }
                sv.AddTable(rowStart, 0, row - rowStart, 2);
                for (int i = 0; i < all_precedents.Count; i++)
                {
                    if ((bool)all_precedents[i].HasFormula)
                    {
                        wks.Cells[rowStart + 1 + i, 1].ApplyStyle(BuiltInStyle.Calculation);
                        wks.Cells[rowStart + 1 + i, 1].Style.WrapText = true;
                        sv.SetRowHeight(rowStart + 1 + i, sv.GetPreferredCellSize(rowStart + 1 + i, 1).Height);
                    }
                }
            }
            wks.RowCount = sv.GetLastNonEmptyRow(NonEmptyItemFlag.Data) + 1;
            sv.SetColumnWidth(1, 500);
            sv.ColumnCount = 2;
            splitContainer3.Panel2Collapsed = false;
            fpSpread2.Visible = true;
            hideReportPaneToolStripMenuItem.Visible = true;
        }

        private void hideReportPaneToolStripMenuItem_Click(object sender, EventArgs e)
        {
            splitContainer3.Panel2Collapsed = true;
            hideReportPaneToolStripMenuItem.Visible = false;
        }

        private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            linkLabel1.LinkVisited = true;
            System.Diagnostics.Process.Start("https://templates.office.com/en-us/Sudoku-puzzle-solver-TM10080972");
        }
    }
}

//
//FormulaTracing.Designer.cs
//

namespace Spread.Calculation.Features
{
    partial class FormulaTracing
    {
        /// <summary> 
        /// Required designer variable.
        /// </summary>
        private System.ComponentModel.IContainer components = null;

        /// <summary> 
        /// Clean up any resources being used.
        /// </summary>
        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        #region Component Designer generated code

        /// <summary> 
        /// Required method for Designer support - do not modify 
        /// the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormulaTracing));
            this.splitContainer1 = new System.Windows.Forms.SplitContainer();
            this.splitContainer2 = new System.Windows.Forms.SplitContainer();
            this.linkLabel1 = new System.Windows.Forms.LinkLabel();
            this.nameBox1 = new FarPoint.Win.Spread.NameBox();
            this.fpSpread1 = new FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None, ((object)(resources.GetObject("pnlMain.Controls"))));
            this.fpSpread1_Sheet1 = this.fpSpread1.GetSheet(0);
            this.formulaTextBox1 = new FarPoint.Win.Spread.FormulaTextBox();
            this.splitContainer3 = new System.Windows.Forms.SplitContainer();
            this.fpSpread2 = new FarPoint.Win.Spread.FpSpread(FarPoint.Win.Spread.LegacyBehaviors.None, ((object)(resources.GetObject("pnlMain.Controls"))));
            this.fpSpread2_Sheet1 = this.fpSpread2.GetSheet(0);
            this.menuStrip1 = new System.Windows.Forms.MenuStrip();
            this.fileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator();
          
            this.formulaTracingToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.showDependentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.showPrecedentsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.removeArrowsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
            this.generateReportToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.hideReportPaneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
            this.pnlMain.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
            this.splitContainer1.Panel1.SuspendLayout();
            this.splitContainer1.Panel2.SuspendLayout();
            this.splitContainer1.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).BeginInit();
            this.splitContainer2.Panel1.SuspendLayout();
            this.splitContainer2.Panel2.SuspendLayout();
            this.splitContainer2.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).BeginInit();
            ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).BeginInit();
            this.splitContainer3.SuspendLayout();
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread2)).BeginInit();
            this.menuStrip1.SuspendLayout();
            this.SuspendLayout();
            // 
            // pnlMain
            // 
            this.splitContainer3.Panel1.Controls.Add(this.fpSpread1);
            // 
            // splitContainer3.Panel2
            // 
            this.splitContainer3.Panel2.Controls.Add(this.fpSpread2);
            this.pnlMain.Size = new System.Drawing.Size(908, 791);
            // 
            // pnlControls
            // 
            this.pnlControls.Size = new System.Drawing.Size(300, 791);
            // 
            // splitContainer1
            // 
            this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.splitContainer1.Location = new System.Drawing.Point(0, 24);
            this.splitContainer1.Name = "splitContainer1";
            this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
            // 
            // splitContainer1.Panel1
            // 
            this.splitContainer1.Panel1.Controls.Add(this.splitContainer2);
            // 
            // splitContainer1.Panel2
            // 
            this.splitContainer1.Panel2.Controls.Add(this.splitContainer3);
            this.splitContainer1.Size = new System.Drawing.Size(1209, 767);
            this.splitContainer1.SplitterDistance = 45;
            this.splitContainer1.TabIndex = 0;
            // 
            // splitContainer2
            // 
            this.splitContainer2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.splitContainer2.Location = new System.Drawing.Point(0, 0);
            this.splitContainer2.Name = "splitContainer2";
            // 
            // splitContainer2.Panel1
            // 
            this.splitContainer2.Panel1.Controls.Add(this.linkLabel1);
            this.splitContainer2.Panel1.Controls.Add(this.nameBox1);
            // 
            // splitContainer2.Panel2
            // 
            this.splitContainer2.Panel2.Controls.Add(this.formulaTextBox1);
            this.splitContainer2.Size = new System.Drawing.Size(1209, 45);
            this.splitContainer2.SplitterDistance = 401;
            this.splitContainer2.TabIndex = 0;
            // 
            // linkLabel1
            // 
            this.linkLabel1.AutoSize = true;
            this.linkLabel1.Location = new System.Drawing.Point(13, 28);
            this.linkLabel1.Name = "linkLabel1";
            this.linkLabel1.Size = new System.Drawing.Size(300, 13);
            this.linkLabel1.TabIndex = 1;
            this.linkLabel1.TabStop = true;
            this.linkLabel1.Text = "Excel template available here from Microsoft Office Templates ";
            this.linkLabel1.LinkClicked += new System.Windows.Forms.LinkLabelLinkClickedEventHandler(this.linkLabel1_LinkClicked);
            // 
            // nameBox1
            // 
            this.nameBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.nameBox1.Location = new System.Drawing.Point(0, 0);
            this.nameBox1.MaxLength = 255;
            this.nameBox1.Name = "nameBox1";
            this.nameBox1.Size = new System.Drawing.Size(401, 21);
            this.nameBox1.TabIndex = 0;
            // Attach nameBox1 to fpSpread1
            this.nameBox1.Attach(this.fpSpread1);
            // 
            // fpSpread1
            // 
            this.fpSpread1.AccessibleDescription = "fpSpread1, Sheet1, Row 0, Column 0";
            this.fpSpread1.BackColor = System.Drawing.SystemColors.Control;
            this.fpSpread1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.fpSpread1.Location = new System.Drawing.Point(0, 14);
            this.fpSpread1.Name = "fpSpread1";
            this.fpSpread1.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.fpSpread1.Size = new System.Drawing.Size(870, 389);
            this.fpSpread1.TabIndex = 0;
            // 
            // formulaTextBox1
            // 
            this.formulaTextBox1.Dock = System.Windows.Forms.DockStyle.Fill;
            this.formulaTextBox1.Location = new System.Drawing.Point(0, 0);
            this.formulaTextBox1.Multiline = false;
            this.formulaTextBox1.Name = "formulaTextBox1";
            this.formulaTextBox1.Size = new System.Drawing.Size(804, 45);
            this.formulaTextBox1.TabIndex = 0;
            // Attach formulaTextBox1 to fpSpread1
            this.formulaTextBox1.Attach(this.fpSpread1);
            // 
            // splitContainer3
            // 
            this.splitContainer3.Dock = System.Windows.Forms.DockStyle.Fill;
            this.splitContainer3.Location = new System.Drawing.Point(0, 0);
            this.splitContainer3.Name = "splitContainer3";
            this.splitContainer3.Panel2Collapsed = true;
            this.splitContainer3.Panel2MinSize = 0;
            this.splitContainer3.Size = new System.Drawing.Size(1209, 718);
            this.splitContainer3.SplitterDistance = 517;
            this.splitContainer3.TabIndex = 0;
            // 
            // fpSpread2
            // 
            this.fpSpread2.AccessibleDescription = "Book1";
            this.fpSpread2.BackColor = System.Drawing.SystemColors.Control;
            this.fpSpread2.Dock = System.Windows.Forms.DockStyle.Fill;
            this.fpSpread2.Location = new System.Drawing.Point(0, 0);
            this.fpSpread2.Name = "fpSpread2";
            this.fpSpread2.RightToLeft = System.Windows.Forms.RightToLeft.No;
            this.fpSpread2.Size = new System.Drawing.Size(908, 791);
            this.fpSpread2.TabIndex = 0;
            this.fpSpread2.Visible = false;
            // 
            // menuStrip1
            // 
            this.menuStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.fileToolStripMenuItem,
            this.formulaTracingToolStripMenuItem});
            this.menuStrip1.Location = new System.Drawing.Point(0, 0);
            this.menuStrip1.Name = "menuStrip1";
            this.menuStrip1.Size = new System.Drawing.Size(1209, 24);
            this.menuStrip1.TabIndex = 1;
            this.menuStrip1.Text = "menuStrip2";
            // 
            // fileToolStripMenuItem
            // 
            this.fileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.openToolStripMenuItem,
            this.toolStripMenuItem1});
            this.fileToolStripMenuItem.Name = "fileToolStripMenuItem";
            this.fileToolStripMenuItem.Size = new System.Drawing.Size(37, 20);
            this.fileToolStripMenuItem.Text = "&File";
            // 
            // openToolStripMenuItem
            // 
            this.openToolStripMenuItem.Name = "openToolStripMenuItem";
            this.openToolStripMenuItem.Size = new System.Drawing.Size(103, 22);
            this.openToolStripMenuItem.Text = "&Open";
            this.openToolStripMenuItem.Click += new System.EventHandler(this.OpenToolStripMenuItem_Click);
            // 
            // toolStripMenuItem1
            // 
            this.toolStripMenuItem1.Name = "toolStripMenuItem1";
            this.toolStripMenuItem1.Size = new System.Drawing.Size(100, 6);
            // 
           
            // formulaTracingToolStripMenuItem
            // 
            this.formulaTracingToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
            this.showDependentsToolStripMenuItem,
            this.showPrecedentsToolStripMenuItem,
            this.removeArrowsToolStripMenuItem,
            this.toolStripMenuItem2,
            this.generateReportToolStripMenuItem,
            this.hideReportPaneToolStripMenuItem});
            this.formulaTracingToolStripMenuItem.Name = "formulaTracingToolStripMenuItem";
            this.formulaTracingToolStripMenuItem.Size = new System.Drawing.Size(105, 20);
            this.formulaTracingToolStripMenuItem.Text = "Formula &Tracing";
            // 
            // showDependentsToolStripMenuItem
            // 
            this.showDependentsToolStripMenuItem.Name = "showDependentsToolStripMenuItem";
            this.showDependentsToolStripMenuItem.Size = new System.Drawing.Size(169, 22);
            this.showDependentsToolStripMenuItem.Text = "Show &Dependents";
            this.showDependentsToolStripMenuItem.Click += new System.EventHandler(this.ShowDependentsToolStripMenuItem_Click);
            // 
            // showPrecedentsToolStripMenuItem
            // 
            this.showPrecedentsToolStripMenuItem.Name = "showPrecedentsToolStripMenuItem";
            this.showPrecedentsToolStripMenuItem.Size = new System.Drawing.Size(169, 22);
            this.showPrecedentsToolStripMenuItem.Text = "Show &Precedents";
            this.showPrecedentsToolStripMenuItem.Click += new System.EventHandler(this.ShowPrecedentsToolStripMenuItem_Click);
            // 
            // removeArrowsToolStripMenuItem
            // 
            this.removeArrowsToolStripMenuItem.Name = "removeArrowsToolStripMenuItem";
            this.removeArrowsToolStripMenuItem.Size = new System.Drawing.Size(169, 22);
            this.removeArrowsToolStripMenuItem.Text = "Remove Arrows";
            this.removeArrowsToolStripMenuItem.Click += new System.EventHandler(this.RemoveArrowsToolStripMenuItem_Click);
            // 
            // toolStripMenuItem2
            // 
            this.toolStripMenuItem2.Name = "toolStripMenuItem2";
            this.toolStripMenuItem2.Size = new System.Drawing.Size(166, 6);
            // 
            // generateReportToolStripMenuItem
            // 
            this.generateReportToolStripMenuItem.Name = "generateReportToolStripMenuItem";
            this.generateReportToolStripMenuItem.Size = new System.Drawing.Size(169, 22);
            this.generateReportToolStripMenuItem.Text = "Generate &Report";
            this.generateReportToolStripMenuItem.Click += new System.EventHandler(this.GenerateReportToolStripMenuItem_Click);
            // 
            // hideReportPaneToolStripMenuItem
            // 
            this.hideReportPaneToolStripMenuItem.Name = "hideReportPaneToolStripMenuItem";
            this.hideReportPaneToolStripMenuItem.Size = new System.Drawing.Size(169, 22);
            this.hideReportPaneToolStripMenuItem.Text = "&Hide Report Pane";
            this.hideReportPaneToolStripMenuItem.Visible = false;
            this.hideReportPaneToolStripMenuItem.Click += new System.EventHandler(this.hideReportPaneToolStripMenuItem_Click);
            // 
            // FormulaTracing
            // 
            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.Controls.Add(this.splitContainer1);
            this.Controls.Add(this.menuStrip1);
            this.Name = "FormulaTracing";
            this.Size = new System.Drawing.Size(1209, 791);
            this.Controls.SetChildIndex(this.menuStrip1, 0);
            this.Controls.SetChildIndex(this.splitContainer1, 0);
            this.pnlMain.ResumeLayout(false);
            this.splitContainer1.Panel1.ResumeLayout(false);
            this.splitContainer1.Panel2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
            this.splitContainer1.ResumeLayout(false);
            this.splitContainer2.Panel1.ResumeLayout(false);
            this.splitContainer2.Panel1.PerformLayout();
            this.splitContainer2.Panel2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.splitContainer2)).EndInit();
            this.splitContainer2.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread1)).EndInit();
            ((System.ComponentModel.ISupportInitialize)(this.splitContainer3)).EndInit();
            this.splitContainer3.ResumeLayout(false);
            ((System.ComponentModel.ISupportInitialize)(this.fpSpread2)).EndInit();
            this.menuStrip1.ResumeLayout(false);
            this.menuStrip1.PerformLayout();
            this.ResumeLayout(false);
            this.PerformLayout();

        }

        #endregion
        private System.Windows.Forms.SplitContainer splitContainer1;
        private System.Windows.Forms.SplitContainer splitContainer2;
        private FarPoint.Win.Spread.NameBox nameBox1;
        private FarPoint.Win.Spread.FormulaTextBox formulaTextBox1;
        private System.Windows.Forms.SplitContainer splitContainer3;
               private System.Windows.Forms.MenuStrip menuStrip1;
        private System.Windows.Forms.ToolStripMenuItem fileToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem openToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripMenuItem1;
        private System.Windows.Forms.ToolStripMenuItem formulaTracingToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem showDependentsToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem showPrecedentsToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem removeArrowsToolStripMenuItem;
        private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
        private System.Windows.Forms.ToolStripMenuItem generateReportToolStripMenuItem;
        private System.Windows.Forms.ToolStripMenuItem hideReportPaneToolStripMenuItem;
        private System.Windows.Forms.LinkLabel linkLabel1;
        private FarPoint.Win.Spread.FpSpread fpSpread2;
        private FarPoint.Win.Spread.FpSpread fpSpread1;
        private FarPoint.Win.Spread.SheetView fpSpread1_Sheet1;
        private FarPoint.Win.Spread.SheetView fpSpread2_Sheet1;
    }
}

//
//RecalculateAction.cs
//

using FarPoint.Win.Spread;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Spread.Calculation.Features
{
    class RecalculateAction : FarPoint.Win.Spread.Action
    {
        public override void PerformAction(object sender)
        {
            SpreadView sv = sender as FarPoint.Win.Spread.SpreadView;
            sv.Sheets[sv.ActiveSheetIndex].Recalculate();
        }
    }
}
